int find(vector<int>& ages, int mode) {
    int left = -1, right = ages.size(), mid = (left + right) >> 1;
    while (left + 1 != right) {
        (ages[mid] < mode ? left : right) = mid;
        mid = (left + right) >> 1;
    }
    // cout << mode << ' ' << left << endl;
    return right;
}
class Solution {
public:
    int numFriendRequests(vector<int>& ages) {
        int n = ages.size(),ret = 0;
        sort(ages.begin(), ages.end());
        int mid = find(ages,100);
        for (int i = 0; i < n; i++) {
            int left = find(ages, (ages[i])/2 + 8);

            int right = find(ages, (ages[i] + 1)) - 1;
            cout << left << right << endl;
            ret += max(right - left + 1, 0);
            if (left <= i && right >= i)
                ret--;
        }
        return ret;
    }
};